package cn.tx.controller;

import cn.tx.constant.MessageConstant;
import cn.tx.entity.PageResult;
import cn.tx.entity.QueryPageBean;
import cn.tx.entity.Result;
import cn.tx.pojo.CheckItem;
import cn.tx.service.CheckItemService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Snake Eyes
 * @PROJECT_NAME: health_parent
 * @DESCRIPTION:
 * @USER: 11647
 * @DATE: 2021/8/25 20:52
 * @Email: 1164763541@qq.com
 */
@RestController
@RequestMapping("checkitem")
public class CheckItemController {
    @Reference
    private CheckItemService checkItemService;

    /**
     * @param checkItem 前台传回的数据
     * @return
     * @author :11647
     * @date ：Created in 2021/8/25  20:59
     * @description：(描述)
     * @modified By：11647
     * @version:
     */
    @RequestMapping("add.do")
    public Result add(@RequestBody CheckItem checkItem) {
        try {
            checkItemService.save(checkItem);
            return new Result(true, MessageConstant.ADD_CHECKITEM_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.ADD_CHECKITEM_FAIL);

        }

    }

    /**
     * @param
     * @return
     * @author :11647
     * @date ：Created in 2021/8/25  23:37
     * @description：(描述) 查询所有数据
     * @modified By：11647
     * @version:
     */
    @RequestMapping("findAll.do")
    public Result findAll() {
        try {
            List<CheckItem> all = checkItemService.findAll();
            return new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS, all);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_CHECKITEM_FAIL);

        }

    }

    /**
     * @param queryPageBean
     * @return
     * @author :11647
     * @date ：Created in 2021/8/26  14:54
     * @description：(描述) 分页查询方法
     * @modified By：11647
     * @version:
     */
    @RequestMapping("findPage.do")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        PageResult pageResult = checkItemService.findPage(
                queryPageBean.getCurrentPage(),
                queryPageBean.getPageSize(),
                queryPageBean.getQueryString());
        return pageResult;
    }

    /**
     * 删除方法
     *
     * @param id
     * @return
     */
    @RequestMapping("delete.do")
    public Result delete(Integer id) {
        try {
            checkItemService.deleteById(id);
            return new Result(true, MessageConstant.DELETE_CHECKITEM_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.DELETE_CHECKITEM_FAIL);

        }
    }
/**
 * @author     :11647
 * @date       ：Created in 2021/8/26  16:57
 * @description：(描述) 修改方法
 * @modified By：11647
 * @version:     
 * @param checkItem
 * @return 
 */
    @RequestMapping("update.do")
    public Result update(@RequestBody CheckItem checkItem) {
        try {
            checkItemService.updateById(checkItem);
            return new Result(true, MessageConstant.EDIT_CHECKITEM_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.EDIT_CHECKITEM_FAIL);

        }
    }


}
